import Vue from 'vue';
import VueRouter from 'vue-router';
import Layout from '../views/layout/index.vue';
import Redirect from '../redirect/redirect.vue';
import problemManage from '../views/robotaxi/problem-manage.vue';
import kpiReport from '../views/robotaxi/kpi-report.vue';
import Preview from '../views/robotaxi/preview.vue';
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout
  },
  {
    path: '/layout',
    name: 'layout',
    component: Layout,
    children: [
      // vue缓存
      vueKeepAlive(),
      // 高级筛选
      advanceFilter(),
      // 其他插件
      otherPlugins()
    ]
  }
];
function otherPlugins() {
  return {
    path: 'other-plugin',
    name: 'other-plugin',
    redirect: {
      name: 'editor-text'
    },
    component: Redirect,
    children: [
      {
        path: 'editor-text',
        name: 'editor-text',
        component: () => import('../views/editor-text/vue-quile-editer.vue'),
        meta: {
          moudle: 'other-plugin',
          menu: 'editor-text'
        }
      }
    ]
  };
}
function advanceFilter() {
  return {
    path: 'component',
    name: 'component',
    redirect: {
      name: 'advance-filter'
    },
    component: Redirect,
    children: [
      {
        path: 'advance-filter',
        name: 'advance-filter',
        component: () => import('../views/my-components/advance-filter/Home.vue'),
        meta: {
          moudle: 'component',
          menu: 'advance-filter'
        }
      },
      {
        path: 'vitural-list',
        name: 'vitural-list',
        component: () => import('../views/vitural-list/index.vue'),
        meta: {
          moudle: 'component',
          menu: 'vitural-list'
        }
      },
      {
        path: 'pop-over',
        name: 'pop-over',
        component: () => import('../views/popover/demo.vue'),
        meta: {
          moudle: 'component',
          menu: 'pop-over'
        }
      },
      {
        path: 'message-box',
        name: 'message-box',
        component: () => import('../views/messageBox/index.vue'),
        meta: {
          moudle: 'component',
          menu: 'message-box'
        }
      }
    ]
  };
}
function vueKeepAlive() {
  return {
    path: 'robotaxi',
    name: 'robotaxi',
    redirect: {
      name: 'problem-manage'
    },
    component: Redirect,
    children: [
      {
        path: 'problem-manage',
        name: 'problem-manage',
        component: problemManage,
        meta: {
          moudle: 'robotaxi',
          menu: 'problem-manage',
          keepAlive: true
        }
      },
      {
        path: 'kpi-report',
        name: 'kpi-report',
        component: kpiReport,
        meta: {
          moudle: 'robotaxi',
          menu: 'kpi-report'
        }
      },
      {
        path: 'preview',
        name: 'preview',
        component: Preview,
        meta: {
          moudle: 'robotaxi',
          menu: 'preview'
        }
      }
    ]
  };
}
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes
});

export default router;
